package org.study.zihan.demo;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * Created by dwlijx on 2021/4/26.
 * connect to lijx@zjhcsoft.com
 */
public class BeginThread extends Thread{
    private Socket socket;
    public BeginThread(Socket socket){
        super();
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            InputStreamReader reader = new InputStreamReader(inputStream);
            char[] charArr = new char[1000];
            int readLengrh = -1;
            while ((readLengrh = reader.read(charArr)) != -1){
                String newString = new String(charArr, 0 , readLengrh);
                System.out.println(newString);
            }
            reader.close();
            inputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
